
package Sgdb::TheMainWindow ;
use Sgdb::Utils qw (:DEFAULT
                    window_geometry
                    ) ;

use warnings ;
use strict ;
use integer ;
use bytes ;

init() ;

sub init { 1 }

sub start {

    my $self = shift ;
    my $mw = $mainwindow = new MainWindow () ;

#     $mw->optionAdd('*BorderWidth' => 1);
    $mw -> title ( 'Sgdb                    ' ) ;
    my $twof = args '2frames' ;
    window_geometry $twof ? 'mainwindow-2frame-r' : 'mainwindow', $mw ;
    my $icon = pref_image( 'sgdbtk' ) ;
    $mw -> Icon ( -image => $icon ) ;

    my $l_frame = $self -> left_frame ($mw, $twof) ;
    my $adjuster = $mw -> Adjuster () ;
    my $r_frame = $self -> right_frame ($mw) ;

    unless ( $twof ) {
        $l_frame -> pack (-side => 'left',
                          -fill => 'both',
                          -expand => 1,
                         );
        $adjuster -> packAfter ($l_frame,
                                -side => 'left',
                               );
    }
    $r_frame -> pack(-side => 'left',
                      -fill => 'both',
                      -expand => 1,
                      );
    new Sgdb::TopMenu ($mw) ;
                                # Algo: This is the last 'new' call, it gives a chance
                                # to all others 'new' calls adding their newly created
                                # clusters to the menu hooks before activating them.
    $mw ;
}

sub left_frame {
    my ($self, $topf, $twof, $frame) = @_ ;
    if ( $twof ) {
        $frame = $mainwindow -> Toplevel () ;
        $frame -> title( 'Sgdb' ) ;
        $frame -> iconimage ( pref_image( 'sgdbtk' ) ) ;
#         $frame -> geometry ( pref 'last-geometry-mainwindow' ) ;
        window_geometry 'mainwindow-2frame-l', $frame ;
        hook_add 'open-source-file' => sub { $frame -> raise ($mainwindow) }
          if pref 'auto-raise-source-window';
    }
    else {
        $frame = $topf -> Frame ();
    }
    my $status  = new Sgdb::StatusLine ($frame) ;
    my $control = new Sgdb::ControlPanel ($frame);
    my $source  = new Sgdb::PanesWin ($frame) ;

    $control -> pack (-side => 'top',
                      -fill => 'x',
                      -expand => 0,
                      );
    $source -> pack (-side => 'top',
                     -fill => 'both',
                     -expand => 1,
                     );
    $status -> pack (-side => 'bottom',
                     -fill => 'x',
                     -expand => 0,
                     -anchor => 's',
                     );

    $frame ;
}

sub right_frame {
    my $self = shift ;
    my $topf = shift ;
    my $frame = $topf->Frame (
                              ) ;
    my $data = new Sgdb::DataPanesWin ($frame) ;
    my $adjuster = $topf -> Adjuster ;
    my $prmt = new Sgdb::CommandPrompt ($frame ) ;

    $data -> pack (-side => 'top',
                   -fill => 'both',
                   -expand => 1,
                   );

    $adjuster -> packAfter ($data,
                            -side => 'top',
                            );
    $prmt -> pack (-side => 'top',
                   -fill => 'both',
                   -expand => 1,
                   );

    $frame ;
}

